"""
封装登录注册相关接口

"""
from webbrowser import register

from api import log
from config import HOST


class ApiRegisterLogin:
    #初始化
    def __init__(self,session):
        #获取session
        self.session=session
    #获取图片验证码url
        self._url_img_code=HOST+"/common/public/verifycode/{}"
    #获取手机验证码url
        self._url_phone_code=HOST+"/member/public/sendSms"
    #获取注册接口url
        self._url_register = HOST+"/member/public/reg"
        #获取登录url
        self._url_login = HOST+"/member/public/login"
        #获取查询登录状态url
        self._url_login_status =HOST+"/member/public/islogin"
        #获取图片验证码接口 封装
    def api_img_code(self,random):
        log.info("正在调用图片验证码接口，请求方法为get，请求url：{}".format(self._url_img_code.format(random)))
        #调用get方法
        return self.session.get(url=self._url_img_code.format(random))
    #获取手机短信验证码封装
    def api_phone_code(self,phone,imgVerifyCode):

        # 调用get方法
        data = {
            "phone":phone,
            "imgVerifyCode":imgVerifyCode,
            "type":"reg"
        }
        log.info("正在调用手机验证码接口，请求方法为post，请求url：{}，请求数据为{}".format(self._url_phone_code,data))
        return self.session.post(url=self._url_phone_code,data=data)
    #获取注册接口 封装
    def api_register(self,phone,password,verifycode,phone_code):
        data={
             "phone":phone,
             "password":password,
             "verifycode":verifycode,
             "phone_code":phone_code,
            "dy_server":"on",
            "invite_phone":""
        }
        log.info("正在调用注册接口，请求方法为post，请求url：{}，请求数据为{}".format(self._url_register, data))
        return self.session.post(url=self._url_register,data=data)
    #获取登录接口 封装
    def api_login(self,keywords="13600001121",password="test123"):
        data={
           "keywords":keywords,
           "password":password
       }
        log.info("正在调用注册接口，请求方法为post，请求url：{}，请求数据为{}".format(self._url_login, data))
        return self.session.post(url=self._url_login,data=data)
    #获取查询登录状态接口
    def api_login_status(self):
        log.info("正在调用查询登录接口,请求方法为get，请求url：{}".format(self._url_login_status))
        return self.session.post(url=self._url_login_status)
